package cn.ekuma.epos.datalogic.define.dao.crm;

import cn.ekuma.data.dao.ModifiedLogDAO;
import cn.ekuma.epos.datalogic.define.dao.shard.AddressEntityDAOHelper;
import cn.ekuma.epos.db.table.crm.I_CustomerAddress;
import cn.ekuma.epos.db.table.shard.I_AddressEntityTable;

import com.openbravo.bean.BusinessPartner;
import com.openbravo.bean.crm.CustomerAddress;
import com.openbravo.data.basic.BasicException;
import com.openbravo.data.loader.DataRead;
import com.openbravo.data.loader.DataWrite;
import com.openbravo.data.loader.Datas;
import com.openbravo.data.loader.I_Session;
import com.openbravo.data.loader.TableDefinition;
import com.openbravo.data.model.Field;
import com.openbravo.format.Formats;

public class CustomerAddressDAO extends ModifiedLogDAO<CustomerAddress>{

    public CustomerAddressDAO(I_Session s) {
        super(s);
    }

	@Override
	public TableDefinition getTable() {
		TableDefinition table=AddressEntityDAOHelper.getTable(s, "CUSTOMER_ADDRESS");
		table.addField( new Field(I_CustomerAddress.CUSTOMERID,Datas.STRING,Formats.STRING,BusinessPartner.class));
		table.addField( new Field(I_CustomerAddress.CREATEDATE,Datas.TIMESTAMP,Formats.TIMESTAMP));
		return table;
	}

	@Override
	public void writeInsertValues(DataWrite dp, CustomerAddress obj)
			throws BasicException {
		AddressEntityDAOHelper.writeInsertValues(dp, obj, 1);
		dp.setString(I_AddressEntityTable.ADDRESS_COLUMN_COUNT+1, obj.getCustomerId());
		dp.setTimestamp(I_AddressEntityTable.ADDRESS_COLUMN_COUNT+2, obj.getCreateDate());
		
	}

	@Override
	public Class getSuportClass() {
		return CustomerAddress.class;
	}

	@Override
	public CustomerAddress readValues(DataRead dr, CustomerAddress obj)
			throws BasicException {
		if(obj==null)
			obj=new CustomerAddress();
		AddressEntityDAOHelper.readValues(dr, obj, 1);
		obj.setCustomerId(dr.getString(I_AddressEntityTable.ADDRESS_COLUMN_COUNT+1));
		obj.setCreateDate(dr.getTimestamp(I_AddressEntityTable.ADDRESS_COLUMN_COUNT+2));
		return obj;
	}
}
